package com.yuejian.neusoft.yuejian_24.model;

import com.yuejian.neusoft.yuejian_24.javaBean.Collected;
import com.yuejian.neusoft.yuejian_24.javaBean.Master;
import com.yuejian.neusoft.yuejian_24.javaBean.Success;
import com.yuejian.neusoft.yuejian_24.listener.CollectedListener;
import com.yuejian.neusoft.yuejian_24.listener.ListListener;
import com.yuejian.neusoft.yuejian_24.listener.MasterListener;
import com.yuejian.neusoft.yuejian_24.listener.SuccessListener;
import com.yuejian.neusoft.yuejian_24.service.MasterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by q4549 on 2017/10/13.
 */

public class MasterModel {
    private Retrofit retrofit;
    public MasterModel(){
        retrofit =new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/yuejian/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void masterlist(final ListListener listener){
        MasterService masterService = retrofit.create(MasterService.class);
        Call call = masterService.allmaster();
        Callback<List<Master>> callback = new Callback<List<Master>>() {
            @Override
            public void onResponse(Call<List<Master>> call, Response<List<Master>> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<List<Master>> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
    public void getmaster(String master_id, final MasterListener listener){
        MasterService masterService = retrofit.create(MasterService.class);
        Call call = masterService.getmaster(master_id);
        Callback<Master> callback = new Callback<Master>() {
            @Override
            public void onResponse(Call<Master> call, Response<Master> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Master> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
    public void follow(String master_id, String uid, String type, final SuccessListener listener){
        MasterService masterService = retrofit.create(MasterService.class);
        Call call = masterService.follow(master_id,uid,type);
        Callback<Success> callback = new Callback<Success>() {
            @Override
            public void onResponse(Call<Success> call, Response<Success> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Success> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
    public void isCollected(String master_id, String uid, String type, final CollectedListener listener){
        MasterService masterService = retrofit.create(MasterService.class);
        Call call = masterService.isCollected(master_id,uid,type);
        Callback<Collected> callback = new Callback<Collected>() {
            @Override
            public void onResponse(Call<Collected> call, Response<Collected> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Collected> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
}
